package com.yxy.chatserver.mapper;

import com.yxy.chatserver.domain.po.Friends;
import com.yxy.chatserver.domain.po.User;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户Mapper
 */
@Mapper
public interface UserMapper {

    /**
     * 根据用户名查询用户
     * @param username
     * @return
     */
    @Select("select * from user where username = #{username} limit 1")
    User selectByUsername(String username);

    /**
     * 插入用户
     * @param user
     */
    void insert(User user);

    /**
     * 根据邮箱查询用户
     * @param email
     * @return
     */
    @Select("select * from user where email = #{email} limit 1")
    User selectByEmail(String email);

    /**
     * 根据用户名或邮箱查询用户
     * @param query
     * @return
     */
    @Select("select * from user where username = #{query} or email = #{query} limit 1")
    User selectByusernameOrEmail(String query);

    /**
     * 根据用户id查询用户好友列表
     * @param userId
     * @return
     */
    @Select("select * from friends where user_id = #{userId}")
    List<Friends> queryFriendsList(String userId);

    /**
     * 根据id查询用户
     * @param fromUserId
     * @return
     */
    @Select("select * from user where id = #{fromUserId} limit 1")
    User getById(String fromUserId);

    /**
     * 添加好友
     * @param friends
     */
    void addFriend(Friends friends);

    /**
     * 检查是否为好友
     * @param userId
     * @param friendId
     * @return
     */
    Boolean checkFriend(String userId, String friendId);
}
